<?php

namespace App\Models;

use App\User;
use Illuminate\Database\Eloquent\Model;

class SkuReference extends Model
{
//    use DefaultDatetimeFormat;

    const TABLE = 'yt_sku_reference';

    protected $table = self::TABLE;

    protected $fillable = [
        'date',
        'part_name_en',
        'part_name_cn',
        'sku',
        'level',
        'reference',
        'description',
        'qty',
        'cost',
        'total_cost',
        'cost_note',
        'exchange_rate',
        'suggested_price',
        'profit_pct',
        'profit',
        'annual_return',
        'main_market',
        'de_weekly_qty',
        'de_feference_link',
        'us_weekly_qty',
        'uk_weekly_qty',
        'au_weekly_qty',
        'us_feference_link',
        'uk_feference_link',
        'au_feference_link',
        'note',
        'us_fba',
        'de_fba',
        'factory_no',// 工厂号
        'tq',
        'remark',
        'creator', //创建人
        'combination',
        'combination_num',
        'customs_name_cn',
        'customs_name_en',
        'out_unit',
        'out_unit_qty',
        'brand',
        'car_type',
        'error',
        'is_error',
    ];


//    static $Level = [
//        'Top 10' => '1',
//        'Top 20' => '2',
//        '普通'    => '3',
//    ];

    // Level 层级列表 ['Top 10'=> 1, 'Top 20'=> 2, ...]
    static function levelKeyVal()
    {
        return array_flip(self::levelOptions());
    }


    //Level 层级列表 [ 1=> 'Top 10', 2=>'']
    static function levelOptions()
    {
        return config('yt.safety_stock.goods_type');
    }


    public function user()
    {
        return $this->belongsTo(User::class, 'creator');
    }


    // uk_weekly_qty 默认显示空
    public function getUkWeeklyQtyAttribute($val)
    {
        return $val>0 ? $val : '';
    }

    public function getUsWeeklyQtyAttribute($val)
    {
        return $val>0 ? $val : '';
    }

    public function getAuWeeklyQtyAttribute($val)
    {
        return $val>0 ? $val : '';
    }

    public function getDeWeeklyQtyAttribute($val)
    {
        return $val>0 ? $val : '';
    }

    public function getUsFbaAttribute($val)
    {
        return $val>0 ? $val : '';
    }

    public function getDeFbaAttribute($val)
    {
        return $val>0 ? $val : '';
    }




}
